package com.martin.dms.web.beans;

import java.io.Serializable;
import java.util.List;

import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.binding.validation.ValidationContext;

public class ItemManagementBean implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -6351764363149582605L;

    private String itemNameFilter = "*";

    private Long categoryId;

    private List<Long> itemIds;

    /**
     * @param itemNameFilter the itemNameFilter to set.
     */
    public void setItemNameFilter(String itemNameFilter) {
        this.itemNameFilter = itemNameFilter;
    }

    /**
     * @return the itemNameFilter.
     */
    public String getItemNameFilter() {
        return itemNameFilter;
    }

    /**
     * @param categoryId the categoryId to set.
     */
    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    /**
     * @return the categoryId.
     */
    public Long getCategoryId() {
        return categoryId;
    }

    /**
     * @param itemIds the itemIds to set.
     */
    public void setItemIds(List<Long> itemIds) {
        this.itemIds = itemIds;
    }

    /**
     * @return the itemIds.
     */
    public List<Long> getItemIds() {
        return itemIds;
    }
    
    public void validateItemsManagement(ValidationContext validationContext) {
        MessageContext messageContext = validationContext.getMessageContext();
        String userEvent = validationContext.getUserEvent();
        if (userEvent.equals("delete") || userEvent.equals("edit")) {
            if (itemIds == null || itemIds.size() != 1) {
                messageContext.addMessage(new MessageBuilder().error().code("error.selectOneItem").build());
            }
        }
    }
}
